package com.geeklan.smart.data.remote.oss;

import android.content.Context;

import com.alibaba.sdk.android.oss.ClientConfiguration;
import com.alibaba.sdk.android.oss.OSS;
import com.alibaba.sdk.android.oss.OSSClient;
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;

public class OSSManager {
    public static final String ACCESS_KEY_ID = "LTAI5tG5qrv2WsVShzrRbuS5";
    public static final String ACCESS_KEY_SECRET = "XfCwMNUGwBnMb42FA08yrnBIqPOiqR";
    public static final String ENDPOINT = "oss-cn-shenzhen.aliyuncs.com";
    public static final String BUCKET_NAME = "oss-mml-oss";


    private static OSS oss;

    public static OSS getOSSClient(Context context) {
        if (oss == null) {
            String endpoint = ENDPOINT; // 阿里云 OSS Endpoint
            String accessKeyId = ACCESS_KEY_ID; // 阿里云 AccessKeyId
            String accessKeySecret = ACCESS_KEY_SECRET; // 阿里云 AccessKeySecret

            OSSCredentialProvider credentialProvider =
                    new OSSPlainTextAKSKCredentialProvider(accessKeyId, accessKeySecret);

            ClientConfiguration conf = new ClientConfiguration();
            conf.setConnectionTimeout(15 * 1000); // 连接超时，默认15秒
            conf.setSocketTimeout(15 * 1000); // socket超时，默认15秒
            conf.setMaxConcurrentRequest(5); // 最大并发请求数，默认5个
            conf.setMaxErrorRetry(2); // 失败后最大重试次数，默认2次

            oss = new OSSClient(context, endpoint, credentialProvider, conf);
        }
        return oss;
    }
}
